package pers.leeyns.rd.base;

import java.util.Random;

public class BaseRandom extends Random{
	private static final long serialVersionUID = 9124698498233623145L;

	public BaseRandom(){
		super();
	}
	
	public int nextInt(){
		return this.nextInt();
	}
	
	public int getRangNumber(int min,int max){
		if(max < min) throw new IllegalArgumentException("The parameter Max is less than min");
		return min + getRandomNumber(max - min);
	}
	
	public int getRandomNumber(int number){
		return this.nextInt(number);
	}
	
	/**
	 * 在Range范围中生成 eg: getRandomNumber("100-200");
	 * @param range 范围表示 startNumber-endNumber 如 100-200不包括200
	 * @return
	 */
	public int getRandomNumber(String range){
		String [] ranges = range.split("[-]");
		if(ranges.length != 2){
			throw new IllegalAccessError("Args 'range' error.");
		}
		int min = Integer.parseInt(ranges[0]);
		int max = Integer.parseInt(ranges[1]);
		return getRangNumber(min, max);
	}
	
	/**
	 * 在arrays 中随机获取一个数字
	 * @param arrays
	 * @return
	 */
	public int getRandomNumber(int [] arrays){
		if(arrays == null || arrays.length == 0)  new IllegalArgumentException("The parameter 'arrays' is empty.");
		return arrays[this.nextInt(arrays.length)];
	}
	
	/**
	 * 随机获取对象
	 * @param objects
	 * @return
	 */
	public Object getRandomObject(Object[] objects){
		return objects[this.nextInt(objects.length)];
	}
	
	/**
	 * 生成一个 longNumberLength长度的数字
	 * @param longNumberLength
	 * @return
	 */
	public String getRandomNumberString(int longNumberLength){
		 StringBuffer sbf = new StringBuffer();
		 for(int i = 0;i<longNumberLength ;i++){
			 sbf.append(getRandomNumber(10));
		 }
		 return sbf.toString();
	}
	
//	public static void main(String[] args) {
//		BaseRandom b = new BaseRandom();
//		while(true)
//		System.out.println(b.getRandomNumberString(10));
//	}
}
